package CardDemo;


import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Text {
    public static final String[] suits = {"♥","♠","♣","♦"};

    //买一副牌
    public static List<Card> buyDeck(){
        List<Card> deck = new ArrayList<>(52);
        for (int i = 0; i < suits.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card();
                card.rank = j;
                card.suit = suits[i];
                deck.add(card);
            }
        }

        return deck;
    }

    private static void swap(List<Card> deck, int i, int j) {
        Card tmp = deck.get(i);
        deck.set(i, deck.get(j));
        deck.set(j, tmp);
    }

    private static void shulfe(List<Card> deck){
        Random random = new Random();
        for (int i = deck.size() - 1; i > 0; i--) {
            int r = random.nextInt(i);
            swap(deck, r, i);
        }
    }

    public static void main(String[] args) {
        //买牌
        List<Card> deck = buyDeck();
        System.out.println("买牌");
        System.out.println(deck);

        //洗牌
        System.out.println("洗牌");
        shulfe(deck);
        System.out.println(deck);

        //三人抓牌
        System.out.println("三人抓牌");
        List<List<Card>> hands = new ArrayList<>();
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hands.get(j).add(deck.remove(0));

            }
        }
        System.out.println("a得到的牌");
        System.out.println(hands.get(0));
        System.out.println("b得到的牌");
        System.out.println(hands.get(1));
        System.out.println("c得到的牌");
        System.out.println(hands.get(2));
        System.out.println("剩余的牌");
        System.out.println(deck);


    }
}
